﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JYStockAnalyser.Model;
using JYStockAnalyser.ClientLib;

namespace JYStockAnalyser.WinUI
{
    public partial class FrmSelectGuideLine : Form
    {
        private List<GuideLineType> m_selectedGuideLines;

        public List<GuideLineType> SelectedGuideLines
        {
            get
            {
                if (m_selectedGuideLines == null)
                {
                    m_selectedGuideLines = new List<GuideLineType>();
                }
                return m_selectedGuideLines;
            }
        }

        public FrmSelectGuideLine()
        {
            InitializeComponent();
        }

        private void FrmSelectGuideLine_Load(object sender, EventArgs e)
        {
            m_init();
        }

        private void m_init()
        {
            this.checkedListBox1.Items.Clear();
            this.checkedListBox2.Items.Clear();
            this.checkedListBox3.Items.Clear();

            List<GuideLineType> lines1 = ClientCache.Instance.AllGuideLineTypes["资产负债表"][2];

            foreach (GuideLineType line in lines1)
            {
                if (this.SelectedGuideLines.Contains(line))
                {
                    this.checkedListBox1.Items.Add(line, true);
                }
                else
                {
                    this.checkedListBox1.Items.Add(line, false);
                }
            }

            List<GuideLineType> lines2 = ClientCache.Instance.AllGuideLineTypes["利润分配表"][2];
            foreach (GuideLineType line in lines2)
            {
                if (this.SelectedGuideLines.Contains(line))
                {
                    this.checkedListBox2.Items.Add(line, true);
                }
                else
                {
                    this.checkedListBox2.Items.Add(line, false);
                }
            }

            List<GuideLineType> lines3 = ClientCache.Instance.AllGuideLineTypes["现金流量表"][2];
            foreach (GuideLineType line in lines3)
            {
                if (this.SelectedGuideLines.Contains(line))
                {
                    this.checkedListBox3.Items.Add(line, true);
                }
                else
                {
                    this.checkedListBox3.Items.Add(line, false);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.SelectedGuideLines.Clear();
            foreach (object obj in this.checkedListBox1.CheckedItems)
            {
                this.SelectedGuideLines.Add((GuideLineType)obj);
            }

            foreach (object obj in this.checkedListBox2.CheckedItems)
            {
                this.SelectedGuideLines.Add((GuideLineType)obj);
            }

            foreach (object obj in this.checkedListBox3.CheckedItems)
            {
                this.SelectedGuideLines.Add((GuideLineType)obj);
            }

            if (this.SelectedGuideLines.Count > 10)
            {
                Tool.ShowInformationBox("不能超过10个指标");
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
